package com.ice.work.moment.facade.ticket.mapper;

import com.honeybee.cloud.framework.common.enums.DataStatusEnum;
import com.honeybee.cloud.framework.common.mapper.BaseCovertMapper;
import com.ice.work.moment.facade.ticket.constant.SystemConstant;
import com.ice.work.moment.facade.ticket.dto.ConfigDTO;
import com.ice.work.moment.facade.ticket.param.CaptchaParam;
import com.ice.work.moment.facade.ticket.param.CreateQrCodeParam;
import com.ice.work.moment.facade.ticket.response.CaptchaResponse;
import com.ice.work.moment.facade.ticket.response.ConfigResponse;
import com.ice.work.moment.facade.ticket.response.CreateQrCodeResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.Objects;

/**
 * @Description ResponseConvertMapper
 * @Author DELL
 * @Create 2019-01-09
 * @Since 1.0.0
 */
@Mapper
@SuppressWarnings("all")
public interface ResponseConvertMapper extends BaseCovertMapper {
    ResponseConvertMapper INSTANCE = Mappers.getMapper(ResponseConvertMapper.class);

    default boolean toBoolean(String result) {
        return Objects.equals(result, SystemConstant.SUCCESS_FLG) || Objects.equals(String.valueOf(DataStatusEnum.VALID.key), result);
    }

    /**
     * to toParam
     *
     * @param param
     * @return
     */
    @Mappings({
            @Mapping(source = "loginPasswordCode", target = "loginPasswordCode", qualifiedByName = "toBoolean"),
            @Mapping(source = "sweepLogin", target = "sweepLogin", qualifiedByName = "toBoolean"),
            @Mapping(source = "qrCodeResult", target = "qrCodeResult", qualifiedByName = "toBoolean"),
            @Mapping(source = "uamLogin", target = "uamLogin", qualifiedByName = "toBoolean"),
            @Mapping(source = "login", target = "login", qualifiedByName = "toBoolean")
    })
    ConfigDTO toParam(ConfigResponse response);

    /**
     * to toParam
     *
     * @param param
     * @return
     */
    @Mappings({
            @Mapping(source = "code", target = "success", qualifiedByName = "toBoolean")
    })
    CaptchaParam toParam(CaptchaResponse response);

    /**
     * to toParam
     *
     * @param param
     * @return
     */
    @Mappings({
            @Mapping(source = "code", target = "success", qualifiedByName = "toBoolean")
    })
    CreateQrCodeParam toParam(CreateQrCodeResponse response);

}
